﻿/// <reference path="/ExtJs/adapter/ext-base.js"/>
/// <reference path="/ExtJs/ext-all-debug.js"/>
Ext.namespace('FantastPlatform', 'FantastPlatform.Common');
FantastPlatform.Common.PapeToolBar = Ext.extend(Ext.PagingToolbar, {
    displayInfo: true,
    displayMsg: '当前 {0} - {1}条 /共 {2}条',
    emptyMsg: "无显示数据",
    onRender: function(ct, position) {
        FantastPlatform.Common.PapeToolBar.superclass.onRender.call(this, ct, position);
        var defaultNum = this.defaultNum;
        var pageSizeNum = new Ext.form.NumberField({
            fieldLabel: '显示数据：',
            name: 'page',
            value: eval(defaultNum),
            width: 50,
            msgTarget: 'title',
            allowBlank: false
        });
        var s = this.store;
        this.pageSize = eval(pageSizeNum.value);
        var p = this;
        pageSizeNum.on('change', function() {
            if (this.noSort) {

                p.setPageNumber(eval(this.getValue()));
                s.removeAll();
                s.reload({ params: { start: 0, limit: eval(this.getValue())} });

            } else {

                p.setPageNumber(eval(this.getValue()));
                s.removeAll();
                s.reload({ params: { start: 0, limit: eval(this.getValue()), dir: '', sort: ''} });
            }
        });
        this.add('-', '每页', pageSizeNum, '条记录');
    }
,
    doLoad: function(start) {
        if (this.noSort) {
            var o = {}, pn = this.paramNames;
            o[pn.start] = start;
            o[pn.limit] = this.pageSize;
            if (this.fireEvent('beforechange', this, o) !== false) {
                this.store.load({ params: o });
            }

        } else {
            var o = {}
            if (this.fireEvent('beforechange', this, o) !== false) {
                //            alert(start);
                //            alert(this.pageSize);
                this.store.load({ params: { start: start, limit: this.pageSize, dir: '', sort: ''} });
            }
        }
    },
    setPageNumber: function(value) {
        this.pageSize = value;
    },
    getPageNumber: function() {
        return this.pageSize;
    }
});